<!doctype html>
<html>
<head>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/>
    <meta charset="UTF-8">
    <title>飞机管理</title>

    {% include 'template/baseCss.volt' %}
    <link href="/css/vendor/plane-detail.less" rel="stylesheet/less" type="text/css">
    <script src="/js/less.min.js"></script>
</head>

<body>

<main>

    <div class="title-bar">
        <label class="server-id" id="plane-info-title">飞机基本信息</label>

        <div style="float: right;" class="button {% block hiddenBack %}{% endblock %}" onClick="DataProxy.clickBack()">
            <label class="btn-text">返回</label>
            <img class="del" src="/images/back.png">
        </div>
        <div style="float: right;" class="button" onClick="DataProxy.clickEdit()">
            <label id="btn-edit" class="btn-text">编辑</label>
            <img src="/images/info_edit_edit.png">
        </div>
    </div>
    <div class="info-wrap">

        <table>
            <tr>
                <th>序列号:</th>
                <td><input data-name="uas_serial_id" type="text" disabled="disabled"></td>
            </tr>

            <tr>
                <th>手机号:</th>
                <td><input data-name="phone" data-valid="phone" data-edit="true" type="text" disabled="disabled"></td>
            </tr>
            <tr>
                <th>飞机状态:</th>
                <td><select data-name="plane_type_id" data-edit="true" disabled="disabled">
                        <option value="">请选择</option>
                        {% for id,name in planeTypeList %}
                            <option value="{{ id }}">{{ name }}</option>
                        {% endfor %}
                    </select></td>
            </tr>
            <tr>
                <th>保修到期时间:</th>
                <td><input type="text" data-attr="date" data-edit="true" data-name="expired_at" disabled="disabled"></td>
            </tr>
            <tr>
                <th>所属区域:</th>
                <td><select data-name="plane_area_id" data-edit="true" disabled="disabled">
                        <option value="">请选择</option>
                        {% for id,name in planeAreaList %}
                            <option value="{{ id }}">{{ name }}</option>
                        {% endfor %}
                    </select></td>
            </tr>
            <tr>
                <th>是否投保第三方险:</th>
                <td><select data-name="insurance" data-edit="true" disabled="disabled">
                        <option value="">请选择</option>
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select></td>
            </tr>
            <tr>
                <th>第三方险开始时间:</th>
                <td><input type="text" data-attr="date" data-edit="true" data-name="insurance_begin_at"
                           disabled="disabled"></td>
            </tr>
            <tr>
                <th>是否投保机身险:</th>
                <td><select data-name="fuselage_insurance" data-edit="true" disabled="disabled">
                        <option value="">请选择</option>
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select></td>
            </tr>
            <tr>
                <th>机身险开始时间:</th>
                <td><input type="text" data-attr="date" data-edit="true" data-name="fuselage_begin_at" disabled="disabled"></td>
            </tr>
        </table>
        <table>
            <tr>
                <th>飞机型号:</th>
                <td><select data-name="planeModel_id" data-edit="true" disabled="disabled">
                        <option value="">请选择</option>
                        {% for id,name in planeModelList %}
                            <option value="{{ id }}">{{ name }}</option>
                        {% endfor %}
                    </select></td>
            </tr>
            <tr>
                <th>持有单位:</th>
                <td><input type="text" data-edit="true" data-name="name" disabled="disabled"></td>
            </tr>
            <tr>
                <th>备注:</th>
                <td><input type="text" data-edit="true" data-name="company" disabled="disabled"></td>
            </tr>
            <tr>
                <th>购买时间:</th>
                <td><input type="text" data-attr="date" data-edit="true" data-name="buy_at" disabled="disabled"></td>
            </tr>
            <tr>
                <th>保修公里数:</th>
                <td><input type="text" data-valid="number" data-edit="true" data-name="warranty_kilometer" disabled="disabled"></td>
            </tr>

            <tr>
                <th></th>
                <td></td>
            </tr>
            <tr>
                <th>第三方险结束时间:</th>
                <td><input type="text" data-attr="date" data-edit="true" data-name="insurance_end_at" disabled="disabled"></td>
            </tr>
            <tr>
                <th></th>
                <td></td>
            </tr>
            <tr>
                <th>机身险结束时间:</th>
                <td><input type="text" data-attr="date" data-edit="true" data-name="fuselage_end_at" disabled="disabled"></td>
            </tr>
        </table>

        <div class="title-bar-inner hidden" id="key-info-title">
            <label class="server-id">关联密钥信息</label>

        </div>

        <table id="key-info-contentA" class="hidden">
            <tr>
                <th>密钥ID:</th>
                <td><input type="text" data-name="key_id" disabled="disabled"></td>
            </tr>
            <tr>
                <th>证书类型:</th>
                <td><select data-name="key_type" data-edit="true" disabled="disabled">
                        <option value="">请选择</option>
                        <option value="1">混合证书</option>
                        <option value="0">无限期</option>
                    </select></td>
            </tr>
            <tr>
                <th>试用过期时间:</th>
                <td><input type="text" data-attr="date" data-edit="true" data-name="key_expired_at" disabled="disabled"></td>
            </tr>
            <tr>
                <th>试用公里数:</th>
                <td><input type="text" data-edit="true" data-name="key_kilometer" disabled="disabled"></td>
            </tr>
            <tr>
                <th>图像处理:</th>
                <td><select data-name="key_smart_map" data-edit="true" disabled="disabled">
                        <option value="">请选择</option>
                        <option value="1">可用</option>
                        <option value="0">不可用</option>
                    </select>
                </td>
            </tr>
        </table>
        <table id="key-info-contentB" class="hidden">
            <tr>
                <th>证书:</th>
                <td><input type="text" data-edit="true" data-name="key_key_data" disabled="disabled"></td>
            </tr>
            <tr>
                <th>证书更新时间:</th>
                <td><input type="text" data-attr="date" data-edit="true" data-name="key_created_at" disabled="disabled"></td>
            </tr>
            <tr>
                <th>起始公里数:</th>
                <td><input type="text" data-edit="true" data-name="key_begin_kilometer" disabled="disabled"></td>
            </tr>
            <tr>
                <th>ipad授权过的钥匙id:</th>
                <td><input type="text" data-edit="true" data-name="key_key_id" disabled="disabled"></td>
            </tr>


        </table>

    </div>




    <div>
        <p class="button save-btn hidden" id="button-save" onclick="DataProxy.clickSave()">保 存</p>
    </div>

</main>


</body>

{% include 'template/baseJs.volt' %}

<script>


    var DataProxy = {
        editState: false,

        planeUId: false,
        prePlaneData: false,
        preKeyData: false,
        init: function () {
            DataAttrBinder.init();
            DataValidBinder.bind();
            this.planeUId = getQueryString("uid");
            this.requestDetail();
        },
        clickSave: function () {

            if (DataValidBinder.valid()) {
                //点击保存
                var param = new Object();
                $("[data-edit=true]").each(function () {
                    var item = $(this);
                    var name = item.attr("data-name");
                    var value = item.val();
                    if (value && value != "") {
                        param[name] = value;
                    }
                });
                param['action_key'] = "ACTION_UPDATE";
                param['uas_serial_id'] = $("[data-name=uas_serial_id]").val();
                var keyId=$("[data-name=key_id]").val();
                if(keyId&&keyId!=""){
                    param['key_id'] =keyId;
                }
                feimaPost("/plane/detail", param, function (result) {
                    FAlert("更新成功", function () {

                        DataProxy._updateButtonState();
                    });

                });
            }


        },
        clickBack:function(){
            if (this.editState) {
                FConfirm("您确定放弃编辑吗?", function (result) {
                    if (result) {
                        DataProxy._goBack();
                    }
                });
            }else{
                DataProxy._goBack();
            }
        },
        _goBack:function(){
            var pre=encodeURIComponent(getQueryString("prefilter"));
            var from=getQueryString("from");
            //window.history.back();
            //var his=window.history;
            window.location.href=from+"?prefilter="+pre;
            console.info(his);
        },
        clickEdit: function () {
            if (this.editState) {
                FConfirm("您确定放弃编辑吗?", function (result) {
                    if (result) {
                        DataProxy._updateButtonState();
                    }
                });
            } else {
                //取消编辑
                this._updateButtonState();
            }
        },
        requestDetail: function () {
            feimaPost("/plane/detail", {
                "action_key": "ACTION_DETAIL",
                "plane_uid": this.planeUId
            }, function (result) {
                if (result) {
                    DataProxy.prePlaneData = result.data["plane"];
                    DataProxy.preKeyData = result.data["key"];
                    DataProxy.updatePageData();
                }
            });
        },
        updatePageData: function () {
            if (DataProxy.prePlaneData) {
                this._updateData(DataProxy.prePlaneData, false);
            }
            if (DataProxy.preKeyData) {
                this._updateData(DataProxy.preKeyData, "key_");
                $("#plane-info-title").text("飞机基本信息");
                $("#key-info-content").removeClass("hidden")
                $("#key-info-title").removeClass("hidden");
                $("#key-info-contentA").removeClass("hidden");
                $("#key-info-contentB").removeClass("hidden");
            } else {
                $("#plane-info-title").text("飞机基本信息(无关联密钥)");
                $("#key-info-content").addClass("hidden");
                $("#key-info-title").addClass("hidden");
                $("#key-info-contentA").addClass("hidden");
                $("#key-info-contentB").addClass("hidden");
            }
        },
        _updateData: function (data, preStr) {
            for (var item in data) {
                var value = data[item] ? data[item] : "";
                item = preStr ? (preStr + item) : item;
                if (this._bindValue(item, value)) {
                    continue;
                }
            }
        },
        _bindValue: function (item, value) {
            var jSelector = "input[data-name=" + item + "]";
            var obj = $(jSelector);
            if (obj.length > 0) {
                obj.val(value);
                return true;
            }
            jSelector = "select[data-name=" + item + "]";
            var obj = $(jSelector);
            if (obj.length > 0) {
                obj.val(value);
                return true;
            }
            return false;
        },
        _updateButtonState: function () {
            this.editState = !this.editState;
            $("#btn-edit").text(this.editState ? "取消编辑" : "编辑");
            hCommon.setElementEnable($("[data-edit=true]"), this.editState);
            if (this.editState) {
                $("#button-save").removeClass("hidden");
            } else {
                $("#button-save").addClass("hidden");

            }

        }

    };
    $(function () {

        DataProxy.init();
    });


</script>
</html>






